@extends('Admin.layout.layout')
@section('content')
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>添加</h5>
                    </div>
                    <div class="ibox-content">
                        <form class="form-horizontal m-t" id="signupForm">
                            {{--<div class="form-group">--}}
                                {{--<label class="col-sm-3 control-label">序号：</label>--}}
                                {{--<div class="col-sm-5">--}}
                                    {{--{{$data['id']}}--}}
                                {{--</div>--}}
                            {{--</div>--}}
                            {{csrf_field()}}
                            <input  name="id" value="" class="form-control" type="hidden">

                            <div class="form-group">
                                <label class="col-sm-3 control-label">标题：</label>
                                <div class="col-sm-5">
                                    <input id="" name="title" value="" class="form-control" type="text">
                                </div>
                            </div>
                            <div class="form-group">
                                @inject('menuPresenter','App\Presenters\MenuPresenter')
                                <label class="col-sm-3 control-label">父级分类：</label>
                                <div class="col-sm-8">
                                    <select name="fid" class="form-control">
                                        <option value="0">顶级分类</option>
                                        @foreach($menuPresenter->cateLevelTree() as $item)
                                            <option value="{{$item['cate_id']}}">
                                                {!!  $item['html'] !!}{{ trans($item['title']) }}
                                            </option>
                                        @endforeach
                                    </select>
                                    @include('Admin.layout.tip',['field' => 'fid'])
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">审核：</label>
                                <div class="col-sm-5">
                                    <div class="radio mrd10">
                                        <input type="radio" name="audit" id="radio4" value="1"   class="" style="margin:2px 0 0 0;">
                                        <label for="radio4"> 是</label>
                                    </div>
                                    <div class="radio mrd10">
                                        <input type="radio" name="audit" id="radio3" value="2"  class="" style="margin:2px 0 0 0;">
                                        <label for="radio3"> 否</label>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">推荐：</label>
                                <div class="col-sm-5">
                                    <div class="radio mrd10">
                                        <input type="radio" name="recommend" id="radio1" value="1"  class="" style="margin:2px 0 0 0;">
                                        <label for="radio1"> 是</label>
                                    </div>
                                    <div class="radio mrd10">
                                        <input type="radio" name="recommend" id="radio0" value="0"  class="" style="margin:2px 0 0 0;">
                                        <label for="radio0"> 否</label>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">排序：</label>
                                <div class="col-sm-1">
                                    <input id="" name="sort" value="0" class="form-control" type="text">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">来源：</label>
                                <div class="col-sm-5">
                                    <input id="" name="come_from" value="" class="form-control" type="text">
                                </div>
                            </div>
                            {{--<div class="form-group">--}}
                                {{--<label class="col-sm-3 control-label">作者：</label>--}}
                                {{--<div class="col-sm-5">--}}
                                    {{--<input id="" name="auth" value="" class="form-control" type="text">--}}
                                {{--</div>--}}
                            {{--</div>--}}
                            <div class="form-group">
                                <label class="col-sm-3 control-label">内容：</label>
                                <div class="col-sm-5">
                                    <script id="editor_id" name="content"  style="min-height:300px;" type="text/plain"></script>
                                </div>
                            </div>
                            <div class="modal-footer">
                                <a href="{{asset('/foradmin/article')}}" class="btn btn-default pull-left">返回</a>
                                <button type="button" class="btn btn-primary" id="btn_submit">
                                    确定
                                </button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>

    </div>
    <script src="{!!asset('/laravel-u-editor/ueditor.config.js')!!}"></script>
    <script src="{!!asset('/laravel-u-editor/ueditor.all.min.js')!!}"></script>
    <script>
        $(document).ready(function () {
            var ue_detail = UE.getEditor('editor_id', { initialFrameWidth: null });
            ue_detail.ready(function() {
                ue_detail.execCommand('serverparam', '_token', '{{ csrf_token() }}'); // 设置 CSRF token.
            });
        });

        $('#pid').change(function(){
            var fid=$('#pid').val();
            $.ajax({
                url: '{{url('/foradmin/article')}}/categoryfid/'+fid,
                type: 'get',
                dataType: 'json',
                data: {},
                success: function (data) {
                    if (0 == data.code) {
                        var str="";
                        if(data.data){
                            for (let i of data.data) {
                                str+="<option value='"+i['id']+"'>"+i['title']+"</option>";
                            }
                        }
                        $('#fid').html(str);
                    } else {
                        layer.alert(data.message, {
                            icon: 2
                        });
                    }
                }
            });

        });

        $('#btn_submit').click(function(){
            $.ajax({
                url: '{{url('/foradmin/article')}}',
                type: 'post',
                dataType: 'json',
                data: $('#signupForm').serialize(),
                success: function (data) {
                    if (0 == data.code) {
                        layer.alert(data.message?data.message:data.data, {
                            icon: 1
                        }, function (index) {
                            layer.close(index);
                            location.href='/foradmin/article';
                        });
                    } else {
                        layer.alert(data.message, {
                            icon: 2
                        }, function (index) {
                            layer.close(index);
//                            windows.lacation.href='/foradmin/article';
                        });
                    }
                }
            });
        });
    </script>
@endsection
